<?php
ini_set('html_errors',true); 
ini_set('display_errors',true);

include("../database/db_conn.inc");
$url = urldecode($_REQUEST['url']);
$name = urldecode($_REQUEST['name']);
$email = urldecode($_REQUEST['email']);
$note = urldecode($_REQUEST['note']);


 if ($HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"])
  {
  $ip = $HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"];
  }
  elseif ($HTTP_SERVER_VARS["HTTP_CLIENT_IP"])
  {
  $ip = $HTTP_SERVER_VARS["HTTP_CLIENT_IP"];
  }
 elseif ($HTTP_SERVER_VARS["REMOTE_ADDR"])
 {
 $ip = $HTTP_SERVER_VARS["REMOTE_ADDR"];
 }
 elseif (getenv("HTTP_X_FORWARDED_FOR"))
 {
 $ip = getenv("HTTP_X_FORWARDED_FOR");
 }
 elseif (getenv("HTTP_CLIENT_IP"))
 {
 $ip = getenv("HTTP_CLIENT_IP");
 }
 elseif (getenv("REMOTE_ADDR"))
 {
 $ip = getenv("REMOTE_ADDR");
 }
 else
 {
 $ip = "Unknown";
 }

$iplocation="";
//$iplocation = iconv("gb2312", "utf-8",file_get_contents("http://whois.pconline.com.cn/ip.jsp?ip=$ip"));
$currentdate = date("y-m-d H:i:s");
$strsql = "select * from email_trace where email_address='".$email."' order by email_id desc";
$rs = mysql_query($strsql);

if (mysql_num_rows($rs)>0){
	$arrayres = mysql_fetch_assoc($rs);
	$readtimes = $arrayres["email_readtimes"]+1;
	$strsql = "update email_trace set email_date='".$currentdate."', email_readtimes=".$readtimes." where email_id=".$arrayres["email_id"];
	$rs = mysql_query($strsql) or die("Query failed");
}else {
	$strsql = "insert into email_trace (email_name,email_address,email_ip,email_iplocation,email_date) values ('".$name."','".$email."','".$ip."','".$iplocation."','".$currentdate."')";
	
	$rs1 = mysql_query($strsql) or die("Query failed");
}
include("../database/db_disconn.inc");


Header ('Content-type: image/png');
readfile($url);

?>